package com.lw.alarm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lw.alarm.dao.AlarmServerMapper;
import com.lw.alarm.model.AlarmServer;
import com.lw.alarm.model.enums.ServerStatus;
import com.lw.alarm.service.AlarmServerService;
import com.lw.common.core.dao.BaseDAO;
import com.lw.common.core.service.BaseService;

/**
 * 
 * @Title: UserServiceImpl.java
 * @Package com.lw.service.impl
 * @Description: 用户service
 * @author 刘伟 15818570028@163.com
 * @date 2016年12月21日 下午6:57:07
 * @version V1.0
 */
@Service("alarmServerService")
public class AlarmServerServiceImpl extends BaseService<AlarmServer, Integer> implements AlarmServerService {
	@Resource
	private AlarmServerMapper alarmServerMapper;

	@Override
	public BaseDAO<AlarmServer, Integer> getDao() {
		return alarmServerMapper;
	}

	@Override
	public PageInfo<AlarmServer> findAlarmServerByPage(AlarmServer record, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<AlarmServer> list = alarmServerMapper.findObjectsByPage(record);
		return new PageInfo<AlarmServer>(list);
	}

	/**
	 * 
	 * @Description:增加失败次数
	 * @param alarmServer
	 */
	public void incAlarmServerTimes(Integer id, Integer times) {
		AlarmServer alarmServer = new AlarmServer();
		alarmServer.setFailureTimes(times + 1);
		alarmServer.setId(id);
		alarmServerMapper.updateByPrimaryKeySelective(alarmServer);
	}

	/**
	 * 
	 * @Description:重新设置失败次数
	 * @param alarmServer
	 */
	public void reSetAlarmServerTimes(Integer id, Integer times) {
		if (times == 0)
			return;
		AlarmServer alarmServer = new AlarmServer();
		alarmServer.setFailureTimes(0);
		alarmServer.setId(id);
		alarmServerMapper.updateByPrimaryKeySelective(alarmServer);
	}

	/**
	 * 
	 * @Description:更改服务状态
	 * @param id
	 * @param status
	 */
	public void updateServerStatus(Integer id, ServerStatus status) {
		AlarmServer alarmServer = new AlarmServer();
		alarmServer.setStatus((byte) status.value());
		alarmServer.setId(id);
		alarmServerMapper.updateByPrimaryKeySelective(alarmServer);
	}

}
